-- Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
--
-- this file licensed under the Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
--
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-- PURPOSE.
-- See the Mulan PSL v2 for more details.
--
-- Author: auto generate
-- Create: 2025-10-19
-- Description: DO NOT EDIT; Code generated by "model.lua.mako"
local mdb = require 'mc.mdb'
local class = require 'mc.class_mgnt'
local privilege = require 'mc.privilege'

local can_intf_types = require 'debug.json_types.CAN'
local remote_access_intf_types = require 'debug.json_types.RemoteAccess'
local properties_intf_types = require 'debug.json_types.Properties'

local RemoteAccess = {
    ['mdb_prop_configs'] = {
        ['bmc.kepler.Debug.RemoteAccess.CAN'] = {},
        ['bmc.kepler.Debug.RemoteAccess'] = {},
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_method_configs'] = {
        ['bmc.kepler.Debug.RemoteAccess.CAN'] = {
            ['SendTestBoardcast'] = {
                ['req'] = {
                    {
                        ['baseType'] = 'U8',
                        ['displayDescription'] = 'The channel number of testing canbus.',
                        ['param'] = 'Channel'
                    }
                },
                ['rsp'] = {},
                ['privilege'] = {'ReadOnly'},
                ['displayDescription'] = 'Send a testing boardcast over canbus.',
                ['cmdName'] = 'cantest'
            },
            ['PrintMetrics'] = {
                ['req'] = {
                    {
                        ['baseType'] = 'U8',
                        ['optional'] = true,
                        ['default'] = 255,
                        ['displayDescription'] = 'The channel number of canbus.',
                        ['param'] = 'Channel'
                    }
                },
                ['rsp'] = {
                    {['baseType'] = 'Array', ['items'] = {['$ref'] = '#/defs/DetailItem'}, ['param'] = 'Details'}
                },
                ['privilege'] = {'ReadOnly'},
                ['displayDescription'] = 'Print the metrics of given canbus.',
                ['cmdName'] = 'canmetrics'
            }
        },
        ['bmc.kepler.Debug.RemoteAccess'] = {
            ['GetRemoteProperties'] = {
                ['req'] = {
                    {
                        ['baseType'] = 'String',
                        ['displayDescription'] = 'The identifier of remote BMC, consist of 3 parts: protocol, address and channel. eg: CAN:5/0.',
                        ['param'] = 'Target'
                    }, {
                        ['baseType'] = 'String',
                        ['displayDescription'] = 'The name of object which the remote properties belongs.',
                        ['param'] = 'Object'
                    }, {
                        ['baseType'] = 'String',
                        ['displayDescription'] = 'The name of interface which the remote properties belongs.',
                        ['param'] = 'Interface'
                    },
                    {
                        ['baseType'] = 'String[]',
                        ['displayDescription'] = 'The name list of remote properties.',
                        ['param'] = 'Properties'
                    }
                },
                ['rsp'] = {{['baseType'] = 'Dictionary', ['$ref'] = '#/defs/RemoteProperties', ['param'] = 'Values'}},
                ['privilege'] = {'ReadOnly'},
                ['displayDescription'] = 'Get properties of the object at remote BMC.',
                ['cmdName'] = 'remotegetprop'
            },
            ['RemoteCall'] = {
                ['req'] = {
                    {
                        ['baseType'] = 'String',
                        ['displayDescription'] = 'The identifier of remote BMC, consist of 3 parts: protocol, address and channel. eg: CAN:5/0.',
                        ['param'] = 'Target'
                    }, {
                        ['baseType'] = 'String',
                        ['displayDescription'] = 'The name of object which the remote method belongs.',
                        ['param'] = 'Object'
                    }, {
                        ['baseType'] = 'String',
                        ['displayDescription'] = 'The name of interface which the remote method belongs.',
                        ['param'] = 'Interface'
                    },
                    {
                        ['baseType'] = 'String',
                        ['displayDescription'] = 'The name of remote method.',
                        ['param'] = 'Method'
                    }, {['baseType'] = 'String', ['param'] = 'Signature'}, {
                        ['baseType'] = 'Dictionary',
                        ['$ref'] = '#/defs/MethodArgs',
                        ['optional'] = true,
                        ['default'] = '',
                        ['displayDescription'] = 'The arguments of remote method.',
                        ['param'] = 'Args'
                    }
                },
                ['rsp'] = {{['baseType'] = 'String', ['param'] = 'Response'}},
                ['privilege'] = {'ReadOnly'},
                ['displayDescription'] = 'Call method of the object at remote BMC.',
                ['cmdName'] = 'remotecall'
            }
        }
    },
    ['mdb_classes'] = mdb.get_class_obj('/bmc/kepler/Debug/RemoteAccess'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.Debug.RemoteAccess.CAN'] = {
            ['property_defaults'] = {},
            ['privileges'] = {
                ['methods'] = {['SendTestBoardcast'] = privilege.ReadOnly, ['PrintMetrics'] = privilege.ReadOnly}
            },
            ['interface_types'] = can_intf_types
        },
        ['bmc.kepler.Debug.RemoteAccess'] = {
            ['property_defaults'] = {},
            ['privileges'] = {
                ['methods'] = {['GetRemoteProperties'] = privilege.ReadOnly, ['RemoteCall'] = privilege.ReadOnly}
            },
            ['interface_types'] = remote_access_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local M = {}

function M.init(bus)
    class('RemoteAccess', RemoteAccess):set_bus(bus)
end

-- The callback needs to be registered during app initialization
function M.ImplRemoteAccessCANSendTestBoardcast(cb)
    class('RemoteAccess')['bmc.kepler.Debug.RemoteAccess.CAN'].SendTestBoardcast = function(obj, ctx, ...)
        local req = can_intf_types.SendTestBoardcastReq.new(...):validate(nil, nil, true)
        local rsp = can_intf_types.SendTestBoardcastRsp.new(cb(obj, ctx, req:unpack())):validate()
        return rsp:unpack(true)
    end
end

-- The callback needs to be registered during app initialization
function M.ImplRemoteAccessCANPrintMetrics(cb)
    class('RemoteAccess')['bmc.kepler.Debug.RemoteAccess.CAN'].PrintMetrics = function(obj, ctx, ...)
        local req = can_intf_types.PrintMetricsReq.new(...):validate(nil, nil, true)
        local rsp = can_intf_types.PrintMetricsRsp.new(cb(obj, ctx, req:unpack())):validate()
        return rsp:unpack(true)
    end
end

-- The callback needs to be registered during app initialization
function M.ImplRemoteAccessRemoteAccessGetRemoteProperties(cb)
    class('RemoteAccess')['bmc.kepler.Debug.RemoteAccess'].GetRemoteProperties = function(obj, ctx, ...)
        local req = remote_access_intf_types.GetRemotePropertiesReq.new(...):validate(nil, nil, true)
        local rsp = remote_access_intf_types.GetRemotePropertiesRsp.new(cb(obj, ctx, req:unpack())):validate()
        return rsp:unpack(true)
    end
end

-- The callback needs to be registered during app initialization
function M.ImplRemoteAccessRemoteAccessRemoteCall(cb)
    class('RemoteAccess')['bmc.kepler.Debug.RemoteAccess'].RemoteCall = function(obj, ctx, ...)
        local req = remote_access_intf_types.RemoteCallReq.new(...):validate(nil, nil, true)
        local rsp = remote_access_intf_types.RemoteCallRsp.new(cb(obj, ctx, req:unpack())):validate()
        return rsp:unpack(true)
    end
end

return M
